﻿<cfsilent>
	<cfscript>

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");

		termId = event.getArg("TermID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");

		event.setArg("pageTitle", "教材管理 - 教材征订与发放 - 学期征订计划 - " & academicYear & "-" & academicTerm);
		
		currentTab = event.getArg("TabID", "labInstitute");
		
		sql = "	SELECT
					i.institute_id,i.institute_name,
					COUNT(DISTINCT c.cid) c_count,
					COUNT(DISTINCT cb.bid) b_count
				FROM
					t_course_book cb INNER JOIN t_course c ON cb.cid = c.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
				WHERE
					cb.term_id = :termId 
				GROUP BY
					i.institute_id,i.institute_name
				ORDER BY
					i.institute_name";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_ins = queryObj.execute(sql = sql).getResult();

		targetArgs = structNew();

	</cfscript>
</cfsilent>



<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教材管理</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教材征订计划 - <cfoutput>#academicYear#</cfoutput><cfoutput>#dictAdvice.getTerm(academicTerm)#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="programCourse">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labInstitute">class="active"</cfif> id="labInstitute" tabTarget="Institute">课程任课单位</span>

						<span <cfif currentTab eq "labImport">class="active"</cfif> id="labImport" tabTarget="Import">导入教材征订计划</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Institute" class="tabContent">
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function showCreateFrom() {
							$("form#formCreate").toggleClass("hidden_elem");
							$("div#insList").toggleClass("hidden_elem");
							return void(0);
						}
						// -->
						//]]>				
					</script>
					
					<cfif rs_ins.recordCount>
							
							<div id="insList">
								
								<div class="noticeBlock">
									<div class="operation">
										<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('planDownloadExcel')#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载学期征订计划</span></a>
									</div>
									<h3>开课部门-教材征订计划</h3>
										<p><span class="img icon16x16 message"></span>如果您需要设置新的教材征订信息, <a href="javascript:showCreateFrom();">请点击这里</a></p>
									<hr/>
								</div>

								<div class="clearfix">
									<div class="UICardTable">
                                        <cfloop query="rs_ins">
											<cfset structInsert(targetArgs, "DepID", rs_ins.institute_id, true) />
											<dl>
												<dt>
													<a href="<cfoutput>#buildURL('bookByDepartment', targetArgs)#</cfoutput>">
													<em class="collection"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
														<div><span><cfoutput>#rs_ins.c_count#</cfoutput></span>门课, 需征订<span><cfoutput>#rs_ins.b_count#</cfoutput></span>种教材</div>
													</dd>
													</a>
												</dt>
											</dl>
										</cfloop>
									</div>
								</div>
								
								
								
							</div>
							
						<cfelse>
							<div id="planNotice" class="systemNotice">
								<h3><span class="img icon16x16 info"></span>没有征订信息</h3>
								<p>当前您还没有设置课程所需教材的征订信息, 请通过完善下列表单设置第一个教材征订计划.</p>
							</div>
					</cfif>
					
					<!-- createPublisher -->
					<form id="formCreate" onSubmit="javascript:return processCreate();" class="formWrapper <cfif rs_ins.recordCount>hidden_elem</cfif>" method="post" action="<cfoutput>#buildURL('bookPlanCreateDo')#</cfoutput>">
						
						<input name="TermID" type="hidden" value="<cfoutput>#termId#</cfoutput>" />
						<input name="CourseID" id="CourseID" type="hidden" value="" />
						<input name="BookID" id="BookID" type="hidden" value="" />
						
						<div class="label">
							<b>课程</b>
							<input name="CourseName" id="CourseName" type="text" disabled="disabled" class="typeTextDynamic " verification="required" value="<cfoutput>#event.getArg('CourseName','未指定')#</cfoutput>" /><span id="courseTrigger" class="btnSearch"></span>
						</div>
						
						<div class="label">
							<b>教材</b>
							<input name="BookName" id="BookName" type="text" disabled="disabled" class="typeTextDynamic " verification="required" value="<cfoutput>#event.getArg('BookName','未指定')#</cfoutput>" /><span id="bookTrigger" class="btnSearch"></span>
						</div>
						
						<hr/>

						<div class="label">
							<span class="req">*</span><b>联络人</b>
							<input name="Contract" id="Contract" type="text" class="typeTextTiny" verification="required" maxlength="30" value="<cfoutput>#event.getArg('Contract')#</cfoutput>" />
						</div>

						<div class="label">
							<span class="req">*</span><b>联系电话</b>
							<input name="Telephone" id="Telephone" type="text" class="typeMobile" verification="required" maxlength="30" value="<cfoutput>#event.getArg('Telephone')#</cfoutput>" />
						</div>
						
						<hr/>
						
						<div class="label">
							<span class="req">*</span><b>采购数量</b>
							学生用书
							<input name="ForStudent" id="ForStudent" type="text" class="typeSmallInt" verification="integer" maxlength="6" value="<cfoutput>#event.getArg('ForStudent','0')#</cfoutput>" />
							教师用书
							<input name="ForTeacher" id="ForTeacher" type="text" class="typeTinyInt" verification="integer" maxlength="3" value="<cfoutput>#event.getArg('ForTeacher','0')#</cfoutput>" />
							
							<p class="notice">学生用书数量系统会根据选课情况尝试自动统计, 如果尚未完成学生选课 或 新生教材预定, 可以在这里填写计划招生数量.</p>
						</div>
						
						<hr/>

						<div class="label">
							<span class="req">*</span><b>价格预算</b>
							定价
							<input name="Prise" id="Prise" type="text" class="typeSmallInt" verification="double" maxlength="7" value="<cfoutput>#event.getArg('Prise','0.00')#</cfoutput>" />
							实际售价
							<input name="Charge" id="Charge" type="text" class="typeSmallInt" verification="double" maxlength="7" value="<cfoutput>#event.getArg('Charge','0.00')#</cfoutput>" />
							
							<div style="width:160px; float:right;">
								折扣率
								<span id="minusDiscount" class="btnMinus">-</span><input name="Discount" id="Discount" type="text" class="typeTinyInt" verification="double" maxlength="4" value="<cfoutput>#event.getArg('Discount','1.00')#</cfoutput>" /><span id="plusDiscount" class="btnPlus">+</span>
							</div>
							
							<p class="notice">此处价格在教材入库时会自动进行更正, 如果无法在入库前确认教材价格, 可以保留为默认值</p>
						</div>

						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="提交" />
							<input onclick="showCreateFrom();" class="button1" type="reset" value="返回" />
						</div>
						
					</form>
					
					<div id="courseBox" class="hidden_elem">
						
						<form id="formSearchCourse" class="formWrapper Transparent" method="post">
							<div class="label">
								<b>课程</b>
								<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							</div>
							<hr/>
							<div class="lable">
								<input class="button1" type="submit" value="搜索课程" />
								<input id="formSearchCourseReset" class="button" type="button" value="返回" />
							</div>
						</form>
						
						<div id="formSearchCourseResult"></div>
						
					</div>
					<div id="bookBox" class="hidden_elem">
					
						<form id="formSearchBook" class="formWrapper Transparent" method="post">
							<div class="label">
								<b>教材</b>
								<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							</div>
							<hr/>
							<div class="lable">
								<input class="button1" type="submit" value="搜索教材" />
								<input id="formSearchBookReset" class="button" type="button" value="返回" />
							</div>
						</form>
						
						<div id="formSearchBookResult"></div>
					
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						
						function processCreate() {
							
							var courseId = $("#CourseID").val();
							var bookId = $("#BookID").val();
							
							if (courseId != "") {
									
								if (bookId != "") {
									return processVerfiyForm('formCreate');
								} else {
									alert("请先指定课程所使用的教材");
									
									$("form#formCreate").addClass("hidden_elem");
									$("div#bookBox").removeClass("hidden_elem");
									$("div#planNotice").addClass("hidden_elem");
									
									return false;
								}
									
							}
							else {
								alert("请先指定课程");
									
								/* courseSearcher */
								$("form#formCreate").addClass("hidden_elem");
								$("div#courseBox").removeClass("hidden_elem");
								$("div#planNotice").addClass("hidden_elem");
								
								return false;
							}
						}
						
						$("span#bookTrigger").click(function(){

							$("form#formCreate").addClass("hidden_elem");
							$("div#bookBox").removeClass("hidden_elem");
							$("div#planNotice").addClass("hidden_elem");

						});
						
						$("span#courseTrigger").click(function(){

							$("form#formCreate").addClass("hidden_elem");
							$("div#courseBox").removeClass("hidden_elem");
							$("div#planNotice").addClass("hidden_elem");

						});
						
						$("input#formSearchBookReset").click(function(){
								
							$("form#formCreate").removeClass("hidden_elem");
							$("div#bookBox").addClass("hidden_elem");
							$("div#planNotice").removeClass("hidden_elem");
								
						});
						
						$("input#formSearchCourseReset").click(function(){
								
							$("form#formCreate").removeClass("hidden_elem");
							$("div#courseBox").addClass("hidden_elem");
							$("div#planNotice").removeClass("hidden_elem");
								
						});
						
						$("#formSearchBook").submit(function(){
							
							if (processVerfiyForm('formSearchBook')) {
								
								$.getJSON(
											'<cfoutput>#buildURL("getBookByKeywords")#</cfoutput>',
											{
												'Keywords': $("form#formSearchBook input#Keywords").val(),
												'seed': (new Date()).getTime()
											},
											function(data) {

												$div = $("div#formSearchBookResult").html("").removeClass("hidden_elem");
												
												book = data.book;
												publisher = data.publisher;

												for (var j=0; j<publisher.length; j++) {
													
													var $element = $("<div class='noticeBlock'><h3>" + publisher[j][1] + "</h3><hr/></div>");
													
													$element.appendTo($div);
													
													$container = $("<div class='clearfix UICardTable'></div>");
													
													for (var i=0; i<book.length; i++) {
														
														if ( book[i][4] == publisher[j][0] ) {
														
															var $element = $("<dl class='col2'><dt><a><em class='subject'></em><dd><h3>" + book[i][1] + "</h3><div>" + book[i][3] + "<span>" + book[i][2].replace(/YYYY/, '').replace(/\./, ' ver.') + "</span></div></dd></a></dt></dl>");
														
															$element
																	.attr({
																			'BookID' : book[i][0],
																			'BookName' : book[i][1],
																			'BookPrice' : book[i][6]
																			})
																	.click(function(){
															
																		var name = $(this).attr('BookName');
																		var id = $(this).attr('BookID');
																		var price = new Number($(this).attr('BookPrice'));
															
																		$("form#formCreate input#BookID").val(id);
																		$("form#formCreate input#BookName").val(name + "(" + id + ")");
																		$("form#formCreate input#Prise").val(price.toFixed(2));
																		$("form#formCreate input#Charge").val(price.toFixed(2));
															
																		/* backForm */
																		$("#formCreate").removeClass("hidden_elem");
																		$("#bookBox").addClass("hidden_elem");
																												
																	})
																	.appendTo($container);
														}
														
													}
													
													$container.appendTo($div);
													
												}


												
											});
								
							}
							
							return false;
						});
						
						$("#formSearchCourse").submit(function(){
							
							if (processVerfiyForm('formSearchCourse')) {
								
								$.getJSON(
											'<cfoutput>#buildURL("getCourseByKeywords")#</cfoutput>',
											{
												'Keywords': $("form#formSearchCourse input#Keywords").val(),
												'seed': (new Date()).getTime()
											},
											function(data) {
												
												$div = $("div#formSearchCourseResult").html("").removeClass("hidden_elem");
												
												course = data.course;
												institute = data.department;

												for (var j=0; j<institute.length; j++) {
													
													var $element = $("<div class='noticeBlock'><h3>" + institute[j][1] + "</h3><hr/></div>");
													
													$element.appendTo($div);
													
													$container = $("<div class='clearfix UICardTable'></div>");
													
													for (var i=0; i<course.length; i++) {
														
														if ( course[i][4] == institute[j][0] ) {
														
															var credit = new Number(course[i][2]);
													
															var $element = $("<dl><dt><a><em class='collection'></em><dd><h3>" + course[i][1] + "</h3><div>" + course[i][3] + "<span>" + credit.toFixed(2) + "</span>学分</div></dd></a></dt></dl>");
														
															$element
																	.attr({
																			'CourseID' : course[i][0],
																			'CourseName' : course[i][1]
																			})
																	.click(function(){
															
																		var name = $(this).attr('CourseName');
																		var id = $(this).attr('CourseID');
															
																		$("form#formCreate input#CourseID").val(id);
																		$("form#formCreate input#CourseName").val(name + "(" + id + ")");
															
																		/* backForm */
																		$("#formCreate").removeClass("hidden_elem");
																		$("#courseBox").addClass("hidden_elem");
																	})
																	.appendTo($container);
														}
														
													}
													
													$container.appendTo($div);
													
												}


												
											});
								
							}
							
							return false;
						});

						/* plusDiscount 折扣率增加 实际售价降低 */
						$("span#plusDiscount").click(function(){
							
							var discount = parseInt(100*$("input#Discount").val());
							var price = parseInt(100*$("input#Prise").val());
							
							var charge = new Number(price/100);
							var dis = new Number(1);
							
							if ( discount < 95 ) {
								discount = discount + 5;
								
								/* 重新计算折扣率 */
								dis = new Number( discount /100 );
								/* 重新计算价格 */
								charge = new Number( 0.05 + price * discount /10000 );
							
							}
							else {
								discount = 100;
							}

							$("input#Discount").val( dis.toFixed(2) );
							$("input#Charge").val( charge.toFixed(1) );
							
						});
						
						
						/* minusDiscount 折扣率降低 实际售价升高 */
						$("span#minusDiscount").click(function(){

							var discount = parseInt(100*$("input#Discount").val());
							var price = parseInt(100*$("input#Prise").val());
							
							var charge = new Number(0);
							var dis = new Number(0);

							if ( discount > 5 ) {
								discount = discount - 5;
								
								/* 重新计算折扣率 */
								dis = new Number( discount /100 );
								/* 重新计算价格 */
								charge = new Number( 0.05 + price * discount /10000 );
							
							}
							else {
								discount = 0;
							}
							
							$("input#Discount").val( dis.toFixed(2) );
							$("input#Charge").val( charge.toFixed(1) );
							
						});
						
						// -->
						//]]>				
					</script>
					
				</div>
				
				
				<div id="Import" class="tabContent">
					
					<div class="noticeBlock">
						<h3>导入教材征订数据</h3>
						<p><span class="img icon16x16 message"></span>请严格按照如下的数据模板在电子表格文件中录入教材征订数据. 点击<a href="<cfoutput>#buildURL('importBookPlanTemplate')#</cfoutput>">下载教材征订计划录入模板</a>, 在录入信息时请勿更改第一行表头内容.</p>
						<hr/>
						<table>
							<tr>								
								<td>学院</td><td>课程</td><td>ISBN</td><td>定价</td><td>折扣率</td><td>学生用量</td><td>教师用量</td><td>联系人</td><td>联系电话</td>
							</tr>
							<tr>
								<td>学院全称</td><td>课程名称</td><td>教材ISBN编号</td><td>教材价格</td><td>1.00为基准的折扣率<br/>0.8即8折</td><td>发放给学生的教材数量</td><td>教师用书数量</td><td>课程用书负责教师</td><td>负责人电话号码</td>
							</tr>
						</table>
						<hr/>
					</div>
					
					<form target="output" onSubmit="javascript:return processVerfiyForm('formImport');" id="formImport" class="formWrapper" method="post" enctype="multipart/form-data" action="<cfoutput>#buildURL('importBookPlanDo')#</cfoutput>">
						
						<div class="label">
							<span class="req">*</span><b>导入数据文件</b>
							<input name="upload" id="upload" type="file" verification="required" />
						</div>
						
						<div class="lable"><input id="importTrigger" class="button" type="submit" value="导入教材数据" /></div>
					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							$("#importTrigger").click(function(){
								$("#output").attr("src","about:blank").removeClass("hidden_elem");
							});
						});
						// -->
						//]]>
					</script>
					
					
					<iframe name="output" id="output" class="UIframeBox hidden_elem" src="about:blank" frameborder="0"></iframe>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>
				
				